<template>
  <a-modal :visible="modifyVisible" @ok="handleSubmit">
    <div :style="{ display: 'flex' }">
      <a-card :style="{ width: '500px' }" :bordered="false">
        <a-form
          :model="createform"
          :style="{ width: '400px' }"
          @submit="handleSubmit"
        >
          <a-form-item field="name" label="问卷名称">
            <a-input
              v-model="createform.name"
              :placeholder="props.dialogTableValue.name"
              readonly="true"
            />
          </a-form-item>
          <a-form-item field="description" label="问卷描述">
            <a-input
              v-model="createform.description"
              :placeholder="props.dialogTableValue.description"
            />
          </a-form-item>
          <a-form-item field="startTime" label="开始时间">
            <a-date-picker
              v-model="createform.startTime"
              style="width: 200px"
              :default-value="props.dialogTableValue.startTime"
            />
          </a-form-item>
          <a-form-item field="endTime" label="结束时间">
            <a-date-picker
              v-model="createform.endTime"
              style="width: 200px"
              :default-value="props.dialogTableValue.endTime"
            />
          </a-form-item>
          <a-form-item field="answerLimit" label="答卷次数">
            <a-input
              v-model="createform.answerLimit"
              :placeholder="props.dialogTableValue.answerLimit"
            />
          </a-form-item>
        </a-form>
      </a-card>
    </div>
  </a-modal>
</template>

<script setup>
  import { ref } from 'vue-demi';
  import { modifyZuhu } from '@/api/user';
  import { modifySurvey } from '@/api/list';

  const createform = ref({
    id: '',
    name: '',
    description: '',
    answerLimit: '',
    typeId: '3',
    managedBy: '',
    startTime: '',
    endTime: '',
  });

  const emits = defineEmits(['fetchData']);
  const props = defineProps({
    dialogTableValue: {
      type: Object,
      default: () => {},
    },
  });
  const handleSubmit = async () => {
    console.log(props.dialogTableValue);
    createform.value.id = props.dialogTableValue.id;
    // createform.value.questions = props.dialogTableValue.questions;
    createform.value.managedBy = props.dialogTableValue.managedBy;
    // createform.value.typeId = props.dialogTableValue.typeId;
    // 没有则自己赋值
    // 我是真的聪明
    if (createform.value.description === '') {
      createform.value.description = props.dialogTableValue.description;
    }
    if (createform.value.name === '') {
      createform.value.name = props.dialogTableValue.name;
    }
    if (createform.value.answerLimit === '') {
      createform.value.answerLimit = props.dialogTableValue.answerLimit;
    }

    await modifySurvey(createform.value);
    emits('fetchData', 1, 20);
  };
</script>
